<template>
	<!-- 站内消息 -->
	<view class="container">
		<view class="contain_top">
			<text>{{ unReadArr.length }}条未读消息</text>
			<image class="top_img" src="https://tcjyh2022.oss-cn-hangzhou.aliyuncs.com/nywx/clear_notice.svg" mode=""
				@tap="clearNotice"></image>
		</view>
		<view class="contain_body">
			<view class="contain_item1" v-for="(item, index) in noticeList" :key="index">
				<view class="contain_item1_top">
					<view class="item1_top_l">
						<text v-if="item.status == 1" class="top_l_dian"></text>
						<text>{{ item.title }}</text>
					</view>
					<view class="item1_top_r">
						{{ item.createTime }}
					</view>
				</view>
				<view class="item1_bottom">
					{{ item.content }}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import {
	getNoticeListData,
	readData
} from '../../api/api.js'
export default {
	data() {
		return {
			noticeList: [], //0已读 1未读
			page1: 1, // 未读
			limit: 100,
			total: 0, // 未读
			isNoMore: 'nomore',
      unReadArr: []
		}
	},
	// 上拉加载
	onReachBottom() {
		// let _this = this;
		// if (((_this.page2 + 1) * _this.limit) < _this.total) {
		// 	_this.page = _this.page + 1;
		// 	_this.isNoMore = 'loading';
		// 	_this.getNoticeList(2);

		// } else {
		// 	_this.isNoMore = 'nomore';
		// }
	},
	onLoad() {
		this.getNoticeList(1); //获取消息列表
	},
	methods: {
		//获取消息列表
		getNoticeList(n, m) {
			if (m == 1) {
				this.page1 = 1;
				this.noticeList = [];
				this.total = [];
			}
			let data = {
				limit: this.limit,
				page: this.page1,
			}
			getNoticeListData(data).then(res => {
				this.noticeList = res.data.list;
				this.unReadArr = []
				this.noticeList.map(item => {
					if (item.status == 1) {
						this.unReadArr.push(item)
					}
				})
			}).catch(err => {
				console.log(err);
			});
		},
		// 清除已读
		clearNotice() {
			let ids = this.unReadArr.map(item => {
				return item.id
			})
			readData({
				status: 2,
				noticeId: ids
			}).then(res => {
        this.getNoticeList(1, 1);
      })
		}
	}
}
</script>

<style scoped lang="scss">
.container {
	padding: 0 30rpx;

	.contain_top {
		display: flex;
		align-items: center;
		padding: 22rpx 0 20rpx;
		font-size: 26rpx;

		.top_img {
			width: 30rpx;
			height: 30rpx;
			margin-left: 20rpx;
		}
	}

	.contain_body {
		.contain_item1 {
			margin-bottom: 24rpx;
			padding: 30rpx 24rpx;
			background-color: #fff;
			border-radius: 18rpx;

			.contain_item1_top {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.item1_top_l {
					display: flex;
					align-items: center;
					font-size: 28rpx;

					.top_l_dian {
						display: inline-block;
						width: 14rpx;
						height: 14rpx;
						margin-right: 20rpx;
						border-radius: 50%;
						background: #FF774D;
					}
				}

				.item1_top_r {
					font-size: 22rpx;
				}
			}

			.item1_bottom {
				margin-top: 22rpx;
				font-size: 26rpx;
				line-height: 38rpx;
			}
		}

		.contain_item2 {
			color: rgba(0, 0, 0, 0.3);
		}
	}
}</style>
